package com.hejie.common.exception;

import lombok.Getter;

@Getter
public class BusinessException extends RuntimeException {
    private final int errorCode;

    /**
     * 根据错误码枚举抛出异常
     */
    public BusinessException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.errorCode = errorCode.getCode();
    }

    /**
     * 根据错误码枚举和自定义消息抛出异常
     */
    public BusinessException(ErrorCode errorCode, String message) {
        super(message);
        this.errorCode = errorCode.getCode();
    }

    /**
     * 根据错误码和消息抛出异常
     */
    public BusinessException(int errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
    }

    /**
     * 根据错误码、消息和 cause 抛出异常
     */
    public BusinessException(int errorCode, String message, Throwable cause) {
        super(message, cause);
        this.errorCode = errorCode;
    }
}